#include "tank.h"

void Tank::update(bool myturn, int scr_height,int scr_width,int ground_height, Uint8 *keys)
{
	if (y < scr_height-ground_height)   // if above ground
		++vel_y;
	if (y >= scr_height-ground_height)   // if below or on ground
	{
		vel_y = 0;
		y = scr_height-ground_height;
	}
	x += vel_x;
	y += vel_y;
	if (x < 0)
		x = 0;
	if (x > scr_width)
		x = scr_width;
	if (y < 0)
		y = 0;
	if (y > scr_height)
		y = scr_height;
	if (myturn)
	{
		if (keys[SDLK_LEFT])
		{
			vel_x = -1;
		}
		else if (keys[SDLK_RIGHT])
		{
			vel_x = 1;
		}
		else
		{
			vel_x = 0;
		}
		if (keys[SDLK_UP])
		{
			angle -= M_PI/180;
		}
		else if (keys[SDLK_DOWN])
		{
			angle += M_PI/180;
		}
		if (keys[SDLK_PAGEUP] && energy != 100)
		{
			++energy;
		}
		if (keys[SDLK_PAGEDOWN] && energy != 4)
		{
			--energy;
		}
	}
}
